// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.SQLReplaceable;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.Collections;
// import java.util.List;

#include "SQLReturnStatement.h"
#include "../../visitor/SQLASTVisitor.h"

SQLReturnStatement::SQLReturnStatement()
{
}

SQLReturnStatement::SQLReturnStatement(DbType_ptr dbType)
    : SQLStatementImpl(dbType)
{
}

SQLExpr_ptr SQLReturnStatement::getExpr()
{
  return expr;
}

void SQLReturnStatement::setExpr(SQLExpr_ptr expr)
{
  if (expr != nullptr)
  {
    expr->setParent(SharedObject(SQLReturnStatement));
  }
  this->expr = expr;
}

// @Override
void SQLReturnStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLReturnStatement)))
  {
    acceptChild(visitor, expr);
  }
  visitor->endVisit(SharedObject(SQLReturnStatement));
}

SQLObject_ptr SQLReturnStatement::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLReturnStatement>(new SQLReturnStatement());
  std::shared_ptr<SQLReturnStatement> x = std::dynamic_pointer_cast<SQLReturnStatement>(clone_tmp);
  // SQLReturnStatement x = new SQLReturnStatement();
  if (expr != nullptr)
  {
    x->setExpr(std::dynamic_pointer_cast<SQLExpr>(expr->clone()));
  }
  return x;
}

// @Override
SQLObject_list_ptr SQLReturnStatement::getChildren()
{
  SQLObject_list_ptr tmp = std::make_shared<std::list<SQLObject_ptr>>();
  tmp->push_back(this->expr);
  return tmp;
}

// @Override
BOOL_ptr SQLReturnStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (this->expr == expr)
  {
    setExpr(target);
    return BOOL::TRUE;
  }
  return BOOL::FALSE;
}
